using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Kopernikus.Parsing.Lexing
{
    public class LexerActions<TAction> where TAction : class
    {
        private readonly Dictionary<string, TAction> m_actions;
        private readonly Regex m_regex;

        internal LexerActions(Regex regex, Dictionary<string, TAction> actions)
        {
            m_regex = regex;
            m_actions = actions;
        }

        public Regex Regex
        {
            get { return m_regex; }
        }

        public Dictionary<string, TAction> Actions
        {
            get { return m_actions; }
        }

        public LexerActions<TAction> Clone(Converter<TAction, TAction> actionCloner)
        {
            Dictionary<string, TAction> newActions = new Dictionary<string, TAction>(m_actions.Comparer);
            foreach (KeyValuePair<string, TAction> pair in newActions)
            {
                newActions.Add(pair.Key, actionCloner(pair.Value));
            }
            return new LexerActions<TAction>(m_regex, newActions);
        }
    }
}